$(function(){
	//初始化 
	var serch_key = utilModule.getStorage("serch_key");
	onlineIndexDoctor(serch_key);
	$(".key").val(serch_key);
	//医生列表渲染
	function onlineIndexDoctor(realname){
		var param="";
		if(realname=="" ||realname==null){
			param= {"pageNo":1,"pageSize":999};
		}else{
			param= {"pageNo":1,"pageSize":999,"realname":realname,"skilful":realname};
		}
		function callBackSlider(data){
			console.log(data);
			var html = "";
			var json = data.doctorList;
			for (i in json) {
				if(json[i].skilful==undefined){
					json[i].skilful="";
				}
				if(json[i].avatar==undefined){
					json[i].avatar = "../../images/doc-man.png"
				}
				html += '<li v='+json[i].id+'><div class="info"><img src="'+json[i].avatar+'"/>'
						+'<button z='+json[i].imisopen+'>问医生</button>'
						+'<b><p class="name">'+json[i].realname+'<span>'+json[i].deptName+'</span></b></br>'+json[i].doctortitle+'</p>'
						+'<p class="hospital">'+json[i].hospitalName+'</p>'
						+'<p class="mui-ellipsis">擅长：'+json[i].skilful+'</p></div>'
						+'<div class="service font1"><div>服务患者端次数：<span>'+json[i].servicetimes+'</span></div><div>关注人数：<span>'+json[i].concernnumber +'</span></div></div></li>';
			}
			$(".online-serchDoctor ul").empty();
			$(".online-serchDoctor ul").append(html);
			
			$(".online-serchDoctor ul li button").on("tap",function(event){
				event.stopPropagation();
				var imopen = $(this).attr("z");
			 	if(imopen==0){
			 		mui.alert("该医生暂未开通在线需方服务");
			 	}else{
					var doctorId=$(this).parent().parent().attr("v");
					var result=checkUnfinishedOrder(USERID,doctorId);
					if(result==true){
						location.href = "../../html/onlineContinuation/medication-consultation.html?doctorId="+doctorId;
					}else{
						return false;
					}
				}
			});
			
			$(".online-serchDoctor ul li").on("tap",function(event){
				event.stopPropagation();
				var doctorId=$(this).attr("v");
				location.href = "../../html/doctor/doctor-details.html?doctorid="+doctorId;
			});
		}
		onlineContinuationModule.onlineDoctorList(param,callBackSlider);
		utilModule.removeStorage("serch_key");
	}
    $(".submitok").on("click",function(){
    	var key = $(".key").val();
    	onlineIndexDoctor(key);
    })

});
